﻿/*********************************************************************
 版权所有: 版权所有(C) 2010 ,熙软研发部
 模块编号:  RemindDO
 作    者:高文华
 编写日期:2010-3-12
 审    核:
 审核日期:
 描    述:RemindDO 日程提醒  数据访问类
...........................................................................
如果模块有修改，则每次修改添加以下注释(以系统上线后为基准)：

 *********************************************************************/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;

using Cisoft.IntegrationSystem.DataHelper;

namespace Cisoft.Cisoft3G.DAL
{
    /// <summary>
    /// 数据访问类RemindDO。
    /// </summary>
    public class RemindDO
    {
        public RemindDO()
        { }
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return SQLServerHelper.GetMaxID("RM_RemindID", "CG_Remind");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int RM_RemindID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from CG_Remind");
            strSql.Append(" where RM_RemindID=@RM_RemindID ");
            SqlParameter[] parameters = {
					new SqlParameter("@RM_RemindID", SqlDbType.Int,4)};
            parameters[0].Value = RM_RemindID;

            return SQLServerHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Cisoft.Cisoft3G.Model.RemindMO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into CG_Remind(");
            strSql.Append("RM_RemindID,RM_Recive,RM_CreateTime,RM_SMContent,RM_Title,RM_RateType,RM_StandardType,RM_StandardTime,RM_StandardWeeks,RM_StartTime,RM_EndTime,RM_EndType,RM_Status)");
            strSql.Append(" values (");
            strSql.Append("@RM_RemindID,@RM_Recive,@RM_CreateTime,@RM_SMContent,@RM_Title,@RM_RateType,@RM_StandardType,@RM_StandardTime,@RM_StandardWeeks,@RM_StartTime,@RM_EndTime,@RM_EndType,@RM_Status)");
            SqlParameter[] parameters = {
					new SqlParameter("@RM_RemindID", SqlDbType.Int,4),
					new SqlParameter("@RM_Recive", SqlDbType.NVarChar,50),
					new SqlParameter("@RM_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@RM_SMContent", SqlDbType.NVarChar,1000),
					new SqlParameter("@RM_Title", SqlDbType.NVarChar,50),
					new SqlParameter("@RM_RateType", SqlDbType.Int,4),
					new SqlParameter("@RM_StandardType", SqlDbType.Int,4),
					new SqlParameter("@RM_StandardTime", SqlDbType.DateTime),
					new SqlParameter("@RM_StandardWeeks", SqlDbType.NVarChar,50),
					new SqlParameter("@RM_StartTime", SqlDbType.DateTime),
					new SqlParameter("@RM_EndTime", SqlDbType.DateTime),
					new SqlParameter("@RM_EndType", SqlDbType.Int,4),
					new SqlParameter("@RM_Status", SqlDbType.Int,4)};
            parameters[0].Value = model.RM_RemindID;
            parameters[1].Value = model.RM_Recive;
            parameters[2].Value = model.RM_CreateTime;
            parameters[3].Value = model.RM_SMContent;
            parameters[4].Value = model.RM_Title;
            parameters[5].Value = model.RM_RateType;
            parameters[6].Value = model.RM_StandardType;
            parameters[7].Value = model.RM_StandardTime;
            parameters[8].Value = model.RM_StandardWeeks;
            parameters[9].Value = model.RM_StartTime;
            parameters[10].Value = model.RM_EndTime;
            parameters[11].Value = model.RM_EndType;
            parameters[12].Value = model.RM_Status;

            SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Cisoft.Cisoft3G.Model.RemindMO model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update CG_Remind set ");
            strSql.Append("RM_Recive=@RM_Recive,");
            strSql.Append("RM_CreateTime=@RM_CreateTime,");
            strSql.Append("RM_SMContent=@RM_SMContent,");
            strSql.Append("RM_Title=@RM_Title,");
            strSql.Append("RM_RateType=@RM_RateType,");
            strSql.Append("RM_StandardType=@RM_StandardType,");
            strSql.Append("RM_StandardTime=@RM_StandardTime,");
            strSql.Append("RM_StandardWeeks=@RM_StandardWeeks,");
            strSql.Append("RM_StartTime=@RM_StartTime,");
            strSql.Append("RM_EndTime=@RM_EndTime,");
            strSql.Append("RM_EndType=@RM_EndType,");
            strSql.Append("RM_Status=@RM_Status");
            strSql.Append(" where RM_RemindID=@RM_RemindID ");
            SqlParameter[] parameters = {
					new SqlParameter("@RM_RemindID", SqlDbType.Int,4),
					new SqlParameter("@RM_Recive", SqlDbType.NVarChar,50),
					new SqlParameter("@RM_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@RM_SMContent", SqlDbType.NVarChar,1000),
					new SqlParameter("@RM_Title", SqlDbType.NVarChar,50),
					new SqlParameter("@RM_RateType", SqlDbType.Int,4),
					new SqlParameter("@RM_StandardType", SqlDbType.Int,4),
					new SqlParameter("@RM_StandardTime", SqlDbType.DateTime),
					new SqlParameter("@RM_StandardWeeks", SqlDbType.NVarChar,50),
					new SqlParameter("@RM_StartTime", SqlDbType.DateTime),
					new SqlParameter("@RM_EndTime", SqlDbType.DateTime),
					new SqlParameter("@RM_EndType", SqlDbType.Int,4),
					new SqlParameter("@RM_Status", SqlDbType.Int,4)};
            parameters[0].Value = model.RM_RemindID;
            parameters[1].Value = model.RM_Recive;
            parameters[2].Value = model.RM_CreateTime;
            parameters[3].Value = model.RM_SMContent;
            parameters[4].Value = model.RM_Title;
            parameters[5].Value = model.RM_RateType;
            parameters[6].Value = model.RM_StandardType;
            parameters[7].Value = model.RM_StandardTime;
            parameters[8].Value = model.RM_StandardWeeks;
            parameters[9].Value = model.RM_StartTime;
            parameters[10].Value = model.RM_EndTime;
            parameters[11].Value = model.RM_EndType;
            parameters[12].Value = model.RM_Status;

            SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int RM_RemindID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from CG_Remind ");
            strSql.Append(" where RM_RemindID=@RM_RemindID ");
            SqlParameter[] parameters = {
					new SqlParameter("@RM_RemindID", SqlDbType.Int,4)};
            parameters[0].Value = RM_RemindID;

            SQLServerHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Cisoft.Cisoft3G.Model.RemindMO GetModel(int RM_RemindID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 RM_RemindID,RM_Recive,RM_CreateTime,RM_SMContent,RM_Title,RM_RateType,RM_StandardType,RM_StandardTime,RM_StandardWeeks,RM_StartTime,RM_EndTime,RM_EndType,RM_Status from CG_Remind ");
            strSql.Append(" where RM_RemindID=@RM_RemindID ");
            SqlParameter[] parameters = {
					new SqlParameter("@RM_RemindID", SqlDbType.Int,4)};
            parameters[0].Value = RM_RemindID;

            Cisoft.Cisoft3G.Model.RemindMO model = new Cisoft.Cisoft3G.Model.RemindMO();
            DataSet ds = SQLServerHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["RM_RemindID"].ToString() != "")
                {
                    model.RM_RemindID = int.Parse(ds.Tables[0].Rows[0]["RM_RemindID"].ToString());
                }
                model.RM_Recive = ds.Tables[0].Rows[0]["RM_Recive"].ToString();
                if (ds.Tables[0].Rows[0]["RM_CreateTime"].ToString() != "")
                {
                    model.RM_CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["RM_CreateTime"].ToString());
                }
                model.RM_SMContent = ds.Tables[0].Rows[0]["RM_SMContent"].ToString();
                model.RM_Title = ds.Tables[0].Rows[0]["RM_Title"].ToString();
                if (ds.Tables[0].Rows[0]["RM_RateType"].ToString() != "")
                {
                    model.RM_RateType = int.Parse(ds.Tables[0].Rows[0]["RM_RateType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RM_StandardType"].ToString() != "")
                {
                    model.RM_StandardType = int.Parse(ds.Tables[0].Rows[0]["RM_StandardType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RM_StandardTime"].ToString() != "")
                {
                    model.RM_StandardTime = DateTime.Parse(ds.Tables[0].Rows[0]["RM_StandardTime"].ToString());
                }
                model.RM_StandardWeeks = ds.Tables[0].Rows[0]["RM_StandardWeeks"].ToString();
                if (ds.Tables[0].Rows[0]["RM_StartTime"].ToString() != "")
                {
                    model.RM_StartTime = DateTime.Parse(ds.Tables[0].Rows[0]["RM_StartTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RM_EndTime"].ToString() != "")
                {
                    model.RM_EndTime = DateTime.Parse(ds.Tables[0].Rows[0]["RM_EndTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RM_EndType"].ToString() != "")
                {
                    model.RM_EndType = int.Parse(ds.Tables[0].Rows[0]["RM_EndType"].ToString());
                }
                if (ds.Tables[0].Rows[0]["RM_Status"].ToString() != "")
                {
                    model.RM_Status = int.Parse(ds.Tables[0].Rows[0]["RM_Status"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RM_RemindID,RM_Recive,RM_CreateTime,RM_SMContent,RM_Title,RM_RateType,RM_StandardType,RM_StandardTime,RM_StandardWeeks,RM_StartTime,RM_EndTime,RM_EndType,RM_Status ");
            strSql.Append(" FROM CG_Remind ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLServerHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" RM_RemindID,RM_Recive,RM_CreateTime,RM_SMContent,RM_Title,RM_RateType,RM_StandardType,RM_StandardTime,RM_StandardWeeks,RM_StartTime,RM_EndTime,RM_EndType,RM_Status ");
            strSql.Append(" FROM CG_Remind ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return SQLServerHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "CG_Remind";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return SQLServerHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法

        public DataSet GetListWithPage(int pageCurrent, int pageSize, string strWhere)
        {
            DataSet ds = new DataSet();
            SqlParameter[] parameters = {
                    new SqlParameter("@tbname", SqlDbType.VarChar,500),
                    new SqlParameter("@FieldKey", SqlDbType.VarChar,500),
                    new SqlParameter("@PageCurrent", SqlDbType.Int,4),
                    new SqlParameter("@PageSize", SqlDbType.Int,4),
                    new SqlParameter("@FieldShow", SqlDbType.VarChar,50),
                    new SqlParameter("@FieldOrder", SqlDbType.VarChar,500),
                    new SqlParameter("@Where", SqlDbType.VarChar,500),
                    new SqlParameter("@ItemCount", SqlDbType.Int,4),
                    new SqlParameter("@PageCount", SqlDbType.Int,4)
                    };
            parameters[0].Value = "CG_Remind";
            parameters[1].Value = "RM_RemindID";
            parameters[2].Value = pageCurrent;
            parameters[3].Value = pageSize;
            parameters[4].Value = "";
            parameters[5].Value = "RM_CreateTime desc";
            parameters[6].Value = strWhere;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            ds = SQLServerHelper.ExecuteStoredProcedure("sp_PageView", parameters);
            return ds;
        }


        public int GetListCount(int pageCurrent, int pageSize, string strWhere)
        {
            DataSet ds = new DataSet();
            SqlParameter[] parameters = {
                    new SqlParameter("@tbname", SqlDbType.VarChar,500),
                    new SqlParameter("@FieldKey", SqlDbType.VarChar,500),
                    new SqlParameter("@PageCurrent", SqlDbType.Int,4),
                    new SqlParameter("@PageSize", SqlDbType.Int,4),
                    new SqlParameter("@FieldShow", SqlDbType.VarChar,50),
                    new SqlParameter("@FieldOrder", SqlDbType.VarChar,500),
                    new SqlParameter("@Where", SqlDbType.VarChar,500),
                    new SqlParameter("@ItemCount", SqlDbType.Int,4),
                    new SqlParameter("@PageCount", SqlDbType.Int,4)
                    };
            parameters[0].Value = "CG_Remind";
            parameters[1].Value = "RM_RemindID";
            parameters[2].Value = pageCurrent;
            parameters[3].Value = pageSize;
            parameters[4].Value = "";
            parameters[5].Value = "RM_CreateTime desc";
            parameters[6].Value = strWhere;
            parameters[7].Direction = ParameterDirection.Output;
            parameters[8].Direction = ParameterDirection.Output;
            object obj = SQLServerHelper.ExecuteStoredProcedure("sp_PageView", parameters, "@ItemCount");
            return Convert.ToInt32(obj);
        }
    }
}

